<!-- 共享积分 -->
<template>
	<view class="content">
		<view class="title">您现在还有<text>{{point || 0}}</text>积分</view>
		<view class="top x-bc">

			<view class="x-f">
				<image class="logo" :src="logo"></image>
				<view class="left-title tl">赠送数量</view>
			</view>
			<view class="x-bc">
				<input class="tr" type="number" placeholder="请输入赠送数量" v-model="shareData.title" />
			</view>
		</view>
		<view class="bottom">
			<view class="bottom_title tl">备注</view>
			<view class="input_box">
				<input class="input" type="text" placeholder="您想对好友说什么~" v-model="shareData.content" />
			</view>
		</view>
		<view class="btn">
			<button open-type="share">分享</button>
		</view>
	</view>
</template>

<script>
	import {
		mapMutations,
		mapActions,
		mapState,
		mapGetters
	} from 'vuex';
	export default {
		data() {
			return {
				shareData: {
					title: null,
					path: '',
					content: ''
				},
				logo: this.imgUrl + 'menu1.png'
			}
		},
		onLoad() {
			// 获取剩余积分
			this.$store.dispatch('init/get_getSharePoints')
		},
		computed: {
			...mapState({
				key: state => state.member.key, // 分享key值
				user: state => state.user.user, // 会员信息
				point: state => state.init.getSharePoints // 可共享积分
			}),
		},
		async onShareAppMessage(options) {
			if (this.point < this.shareData.title) {
				this.$tools.toast('您可共享的积分不足');
				return;
			}
			if (this.shareData.title == null) {
				this.$tools.toast('请输入赠送数量')
				return;
			}
			let isShare; //是否显示分享弹窗

			let obj = {
				share_points: parseInt(this.shareData.title),
				remark: this.shareData.content
			}
			await this.$store.dispatch('member/get_share_score', obj).then(res => {
				if (res.status == 0) {
					this.$tools.toast(res.info)
					isShare = false
				}
				if (res.status == 1) {
					isShare = true
				}
			})
			if (!isShare) return
			return {
				title: '您的好友赠送了' + this.shareData.content + '积分',
				path: '/pages/login/index?key=' + this.key,
				content: this.shareData.content,
			}

			/**
			 * 获取到 需要共享的积分值,
			 * 用户的会员ID,
			 * 备注信息 - 推送给后端. 
			 * 后端返回 key 值.
			 * 获取key 值之后, 将key 值 绑定在跳转路由之上.
			 * 进入指定页面, 判断是否有携带可以key值.
			 * 如果有携带key值, 将key请求值后端获取数据, 同时判断用户是否有登录. 
			 * 如登录, 且为会员 则进入共享积分领取页面.
			 * 如未登录, 则进入登录页面进行登录, - 登录完成之后再跳转领取积分页面
			 * 点击领取, 后台会返回信息 - 
			 * 验证是否未会员, 非会员提示用户去绑定认证信息. - 绑定完成之后
			 */
		},
	}
</script>

<style lang="scss" scoped>
	@import './index.scss';
</style>
